<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑菜单</title>

    <link rel="stylesheet" href="/static/layui/css/layui.css">

</head>

<body style="padding: 10px;">
    <form class="layui-form">
        <!-- 父菜单id -->
        <input type="hidden" name="pid" value="{$pid}">
        <!-- 当前菜单id -->
        <input type="hidden" name="id" value="{$currunt_menu.id}">


        <!-- 显示上级菜单 -->
        {if ($parent_menu) }
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:green;">上级菜单</span></label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" style="color:#01aaed;" disabled="true"
                    value="{$parent_menu.title}">
            </div>
        </div>
        {/if}

        <!-- 菜单名称 -->
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-inline">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入菜单名称" autocomplete="off"
                    class="layui-input" value="{$currunt_menu.title}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="number" class="layui-input" name="ord" lay-verify="required|number"
                    value="{$currunt_menu.ord}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">控制器</label>
            <div class="layui-input-inline">
                <input type="text" name="controller" required lay-verify="required" placeholder="请输入控制器"
                    autocomplete="off" class="layui-input" value="{$currunt_menu.controller}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">方法</label>
            <div class="layui-input-inline">
                <input type="text" name="method" required lay-verify="required" placeholder="请输入方法" autocomplete="off"
                    class="layui-input" value="{$currunt_menu.method}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否隐藏</label>
            <div class="layui-input-block">
                <input type="checkbox" id="ishidden" name="ishidden" lay-skin="switch" lay-filter="ishiddenSwitch"
                    lay-text="隐藏|显示" value="{$currunt_menu.ishidden}" {$currunt_menu.ishidden==1?'checked':''}>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" id="status" name="status" lay-skin="switch" lay-filter="statusSwitch"
                    lay-text="启用|禁用" value="{$currunt_menu.status}" {$currunt_menu.status==1?'checked':''}>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formSubmit">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>



    <script src="/static/layui/layui.js"></script>
    <script>
        layui.use(['layer', 'form'], function () {
            var layer = layui.layer;
            var $ = layui.jquery;
            var form = layui.form;

            // ishidden开关选择事件
            form.on('switch(ishiddenSwitch)', function (data) {
                if (data.elem.checked) {
                    data.value = 1;
                    $('#ishidden').val(1);
                } else {
                    data.value = 0;
                    $('#ishidden').val(0);
                }
            });

            // status状态开关选择事件
            form.on('switch(statusSwitch)', function (data) {
                if (data.elem.checked) {
                    data.value = 1;
                    $('#status').val(1);
                } else {
                    data.value = 0;
                    $('#status').val(0);
                }
            });

            // 提交编辑
            form.on('submit(formSubmit)', function (data) {
                $.ajax({
                    url: '/admin/menu/edit',
                    type: 'put',
                    async: true,
                    dataType: 'json',
                    data: data.field,
                    success: function (res) {
                        if (res.code == '200') {
                            layer.msg('操作成功', {
                                icon: 6,
                                time: 500
                            }, function () {
                                parent.window.location.reload();
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 5,
                                time: 1000
                            });
                        }
                    }
                });

                return false;
            });
        });

    </script>
</body>

</html>